package a09_贪心算法;

import java.util.Arrays;

/**
 * <p>
 * a17_用最少数量的箭引爆气球复习2
 * </p>
 *
 * @author flyduck
 * @since 2025/2/25
 */
public class a17_用最少数量的箭引爆气球复习2 {
    public static void main(String[] args) {
        a17_用最少数量的箭引爆气球复习2 test = new a17_用最少数量的箭引爆气球复习2();
//        System.out.println(test.findMinArrowShots(new int[][]{{10, 16}, {2, 8}, {1, 6}, {7, 12}}));
        System.out.println(test.findMinArrowShots(new int[][]{{-2147483646,-2147483645}, {2147483646,2147483647}}));
    }
    //[[10,16],[2,8],[1,6],[7,12]]
    //[1,6],[2,8],[7,12],[10,16]
    public int findMinArrowShots(int[][] points) {
        Arrays.sort(points, (item1,item2) -> {
            if(item1[0] > item2[0]){
                return 1;
            }else if(item1[0] < item2[0]){
                return -1;
            }else {
                return 0;
            }
        });

        int result = 1;

        for (int i = 1; i < points.length; i++) {
            if(points[i][0] > points[i-1][1]){
                result++;
            }else {
                points[i][1] = Math.min(points[i-1][1],points[i][1]);
            }
        }
        return result;
    }
}
